<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<style>
    <!--
    -->
    .form-group > label {
        width: 60px;
    }
</style>
<script type="text/javascript">
    var menuids =${sessionScope.menus_session_key}+",";
    var meet = {
        searchFormCallback: function (json) {
            console.log(json);
            if (json.code == 0) {
                var page = json.data;
                if (page.rows.length < 1) {
                    $(this).alertmsg('info', "无数据");
                }
                meet.showGridData(page, 'O');
            } else {
                $(this).alertmsg('error', json.msg);
            }
        },
        showGridData: function (page, domainNo) {
            var pageNum = page.currPage;//当前页页码
            var pageSize = page.pageSize;//每页多少条
            var size = page.size;//当前页有多少条
            var total = page.total;//总条数
            var pages = page.pages;//总页数
            var list = page.rows;

            var trs = "";

            var tempCount = '<tr><td>{tp0}</td><td>{tp1}</td><td>{tp2}</td><td>{tp3}</td><td>{tp4}</td></tr>';

            for (var i = 0; list != null && i < list.length; i++) {
                var operation = '';
                if (menuids.indexOf(",65,") > -1) {
                    operation = operation + '<a class="btn btn-blue" data-icon="info" data-id="cpi"	data-title="查看会议信息" data-height="800" data-width="850" data-mask="true" data-toggle="dialog" href="meet/detail/' + list[i].id + '.shtml">详情</a>';
                }
                if (menuids.indexOf(",66,") > -1) {
                    operation = operation + '&nbsp;<a class="btn btn-blue" data-icon="edit" data-id="cpi"	data-title="编辑会议信息" data-height="800" data-width="850" data-mask="true" data-toggle="dialog" href="meet/page/update.shtml?id=' + list[i].id + '">编辑</a>';
                }
                if (menuids.indexOf(",67,") > -1) {
                    operation = operation + '&nbsp;<a	class="btn btn-red" data-icon="minus" data-mask="true" data-toggle="doajax" data-confirm-msg="请确认是否删除当前会议？" data-callback="doAjaxCallBack"  href="meet/delete/' + list[i].id + '.shtml">删除</a>';
                }
                if (menuids.indexOf(",68,") > -1) {
                    operation = operation + '&nbsp;<a class="btn btn-green" data-icon="sign-out" href="filesupload/word/download/' + list[i].fileNo + '.shtml">下载word文档</a>';
                }

                var tempStr = tempCount
                    .replace("{tp0}", (i + 1))
                    .replace("{tp1}", list[i].name)
                    .replace("{tp2}", typeof(list[i].meetTime) == "undefined" ? "" : list[i].meetTime)
                    .replace("{tp3}", typeof(list[i].creator) == "undefined" ? "" : list[i].creator)
                    .replace("{tp4}", operation);

                trs += tempStr;

                $.CurrentNavtab.find("#meetlist").html("");
                $.CurrentNavtab.find("#meetlist").append(trs);

            }

            $.CurrentNavtab.find("th").css("text-align", "center");
            $.CurrentNavtab.find("td").css("text-align", "center");
            $.CurrentNavtab.find("#total").html(total);
            refreshPageBar(total, pageNum, pageSize);
        }
    };

    $(function () {

        var page = ${page};
        meet.showGridData(page, 'O');

        //查询提交按钮事件
        $.CurrentNavtab.find("#queryform").on("click", function () {
            var meetTime = $.CurrentNavtab.find("#meetTime").val();
            var name = $.CurrentNavtab.find("#name").val();
            var criterias = [];
            if (!Dracula.util.isEmpty(meetTime)) {
                criterias.push({
                    field: 'meetTime',
                    condition: "like",
                    value: meetTime + "%"
                });
            }
            if (!Dracula.util.isEmpty(name)) {
                criterias.push({
                    field: 'name',
                    condition: "like",
                    value: "%" + name + "%"
                });
            }
            var formQuery = {
                currPage: parseInt($.CurrentNavtab.find("#pagerForm > input[name=pageNum]").val()),
                pageSize: parseInt($.CurrentNavtab.find("#pagerForm > input[name=pageSize]").val()),
                criterias: criterias,
                entity: 'business.Meet'
            };
            Dracula.post('query.shtml', formQuery, meet.searchFormCallback);
        });
    });

</script>

<%--查询表单--%>
<div class="bjui-pageHeader"
     style="height: auto; padding-top: 10px; padding-bottom: 10px;">
    <form id="pagerForm" class="pageForm" data-toggle="ajaxsearch" method="post">
        <input type="hidden" id="pageSize" name="pageSize" value="15">
        <input type="hidden" id="pageNum" name="pageNum" value="1">
        <input type="hidden" id="totalsize" name="totalsize">
        <div class="bjui-searchBar">
            <div class="row">
                <div class="col-md-4">
                    <div class="form-group">
                        <label>召开时间：</label>
                        <input type="text" data-pattern="yyyy-MM"
                               id="meetTime" name="meetTime" data-toggle="datepicker" data-max-date="%y-%M"
                               class="form-control"/>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label>会议名称</label>
                        <input type="text" id="name" name="name" class="form-control"/>
                    </div>
                </div>
                <div class="col-md-8">
                    <div class="form-group " align="center">
                        <button id="queryform" class="btn-primary" data-icon="search">查询</button>
                        &nbsp; <a class="btn btn-orange" href="javascript:;"
                                  onclick="resetFormAndSearch()" data-icon="undo">清空查询</a>
                    </div>
                </div>
                <c:if test="${fn:contains(sessionScope.menus_session_key,',64,')}">
                    <div class="col-md-4">
                        <div class="form-group " align="center">
                            <a class="btn btn-blue" data-icon="plus" data-id="addtask"
                               data-title="创建新会议" data-height="800" data-width="850"
                               data-mask="true" data-toggle="dialog" data-resizable=false data-maxable=false
                               href="meet/page/add.shtml">创建新会议</a>

                        </div>
                    </div>
                </c:if>
            </div>
        </div>
    </form>
</div>

<%--信息表格--%>
<div class="bjui-pageContent tableContent" id="contentList">
    <table data-toggle="tablefixed" data-width="100%" data-nowrap="true" id="meettable">
        <thead>
        <tr id="meettr">
            <th width="40">编号 <br></th>
            <th width="120">会议名称<br></th>
            <th width="120">召开时间<br></th>
            <th width="120">创建人<br></th>
            <th width="200">操作<br></th>
        </tr>
        </thead>
        <tbody id="meetlist">
        </tbody>
    </table>
</div>

<%--分页信息栏--%>
<jsp:include page="../paging.jsp"></jsp:include>